package com.sk.cardeal.act.recommend;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sk.cardeal.R;
import com.sk.cardeal.adapter.MyPagerAdapter;
import com.sk.cardeal.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by sk on 2017/12/14.
 */

public class RecommendFragment extends BaseFragment {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.my_table)
    TabLayout myTable;
    @BindView(R.id.my_pager)
    ViewPager myPager;
    Unbinder unbinder;
    private List<Fragment> fragmentList;

    @Override
    protected int getContentView() {
        return R.layout.fragment_recommend;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initFragments();
    }

    private void initFragments() {

        String[] consult_array = getResources().getStringArray(R.array.consult_array);
        fragmentList = new ArrayList<>();
        for (int i = 0; i < consult_array.length; i++) {
            RecommendConsultFragment recommendConsultFragment = RecommendConsultFragment.getInstance(i+1);
            fragmentList.add(recommendConsultFragment);
        }

        MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager(), getResources().getStringArray(R.array.consult_array), fragmentList);
        myPager.setAdapter(adapter);
        myTable.setupWithViewPager(myPager);
    }
}
